package hibernate_advanced_apply.object_inherit_mapping.singletable.single_table_annotation.source;

import javax.persistence.*;

/**
 * @author Administrator
 * @create 2019-01-06 13:39
 * @desc 人类父类持久化类(注解)
 **/

//注明实体类
@Entity

//注明实体类映射的表名
@Table(name="person")

//设置继承策略为单表继承
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)

//设置鉴定器为type字段,类型为String
@DiscriminatorColumn(name="type",discriminatorType =DiscriminatorType.STRING)

public class Person {

    @Id//主键注解必须注明

    /*
        不设置生成策略默认为auto(程序手动创建)
        非主键字段可以不注明
        ***区别不同实体类的type字段不需设置,程序自动添加
     */
    //@GeneratedValue(strategy = GenerationType.AUTO)//设置主键生成策略为由程序控制
    //@Column(name="id")
    private int id;

    //@Column(name="name")
    private String name;

   // @Column(name="sex")
    private String sex;

    //@Column(name="age")
    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
